package com.httpdemo.http_teaching_server.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/status")
public class StatusCodeController {

    /**
     * 万能状态码路由
     * 示例：GET /demo/status/418 -> 418 I'm a teapot
     */
//    @GetMapping("/{code}")
//    public ResponseEntity<Void> status(@PathVariable int code) {
//        return ResponseEntity.status(code).build();
//    }
    @GetMapping("/{code}")
    public ResponseEntity<Void> status(@PathVariable int code) {
        HttpStatus status = HttpStatus.resolve(code);
        return ResponseEntity.status(status != null ? status : HttpStatus.valueOf(code)).build();
    }
}